﻿using System;

namespace BookStore
{
    public abstract class Item : IStoreable, IRateable
    {
        protected static int idcounter = 0;
        private decimal price;
        private string name;

	    public string Name
	    {
		    get { return this.name;}
		    set { name = value;}
	    }

        public decimal Price
        {
            get { return this.price; }
            set { price = value; }
        }
        private int id;

        public int Id
        {
            get { return this.id; }
            private set { id = value; }
        }
        
        private Publisher publisher;

        public Publisher Publisher
        {
            get { return this.publisher; }
            set { publisher = value; }
        }
               
        private double rating;

        public double Rating
        {
            get { return this.rating; }
            set { rating = value; }
        }

        private string contentType;

        public string ContentType
        {
            get { return this.contentType; }
            set { contentType = value; }
        }

        public int YearOfPublishing { get; set; }

        //Initializes the "id" field of the object
        public void InitID ()
        {
            if (this.id == 0)
            {
                Item.idcounter++;
                this.Id = Item.idcounter;
            }
        }

        public Item(string name, Publisher publisher, decimal price, string contentType)
        {
            this.Publisher = publisher;
            this.Name = name;
            this.Price = price;
            this.ContentType = contentType;
            InitID();
        }

        public virtual decimal GetPrice()
        {
            return this.Price;
        }

        public override string ToString()
        {
            return String.Format("{0} {1} {2} - {3:c}", this.Name, this.Publisher, this.contentType, GetPrice());
        }
    }
}
